package plutuscat.shishicai.timer;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import plutuscat.shishicai.service.LotteryService;

/**
*
* @author dw_chenqi
* @date 2016年5月13日上午9:31:11
*/
@Component
public class SyncLotteryDataTimer {

	private static final Logger log = LoggerFactory.getLogger(SyncLotteryDataTimer.class);

	@Autowired
	LotteryService lotteryService;

	public SyncLotteryDataTimer() {
		log.info("初始化彩票同步任务!");
		doSyncJob();
	}

	public void doSyncJob() {
		Timer timer = new Timer("彩票同步Timer");
		//表里存储开奖时间,一起扒到并解析
		Date firstTime = DateUtils.addMinutes(new Date(), 1);// 一分钟之后执行
		timer.scheduleAtFixedRate(new TimerTask() {

			@Override
			public void run() {
				log.info("执行彩票同步任务!");
				lotteryService.syncLotteryData();
			}
		}, firstTime, 3*60 * 1000); //白天5分钟执行一次
	}

}
